import {
  list, queryCreateTenant,
  deleteByIds, queryInAuth, queryTypes,
  change, queryById, create,queryEnable
} from '@/api/role'

const getDefaultState = () => {
  return {

  }
}

const state = getDefaultState()

const mutations = {

}

const actions = {
  /**
   * 查询角色列表
   * @param {Object} searParams 检索参数
   */
  list({ commit }, searParams) {
    return new Promise(function (resolve, reject) {
      list(searParams).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 查询角色创建人列表
   */
  getCreateTenant() {
    return new Promise(function (resolve, reject) {
      queryCreateTenant().then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 查询角色类型列表
   */
  getTypes() {
    return new Promise(function (resolve, reject) {
      queryTypes().then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 查询角色列表
   */
  getInAuth() {
    return new Promise(function (resolve, reject) {
      queryInAuth().then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 查询角色列表
   */
  getEnable() {
    return new Promise(function (resolve, reject) {
      queryEnable().then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 通过id查询角色
   * @param {Number} roleId 角色id
   */
  getById({ commit }, roleId) {
    return new Promise(function (resolve, reject) {
      queryById(roleId).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 删除角色
   * @param {*} roleIds 角色id
   */
  removeByIds({ commit }, roleIds) {
    return new Promise(function (resolve, reject) {
      deleteByIds(roleIds).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 修改角色
   * @param {*} roleForm 角色数据
   */
  modifyById({ commit }, roleForm) {
    return new Promise(function (resolve, reject) {
      change(roleForm).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  },
  /**
   * 创建角色
   * @param {*} roleForm 角色数据
   */
  create({ commit }, roleForm) {
    return new Promise(function (resolve, reject) {
      create(roleForm).then(res => {
        resolve(res)
      }).catch(err => {
        reject(err)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
